<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>非遗百科 - 分类浏览</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background-color: #f5f5f5;
            padding: 0;
            margin: 0;
        }

        /* 头部导航栏样式 */
        .header {
            background-color: rgb(135, 73, 73);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            padding: 20px 25px;
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
            position: sticky;
            top: 0;
            z-index: 1001;
        }

        /* 左侧导航组 */
        .nav-left {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        /* 中间主题切换 */
        .nav-center {
            display: flex;
            align-items: center;
            flex: 1;
            justify-content: center;
        }

        /* 右侧用户设置 */
        .nav-right {
            display: flex;
            align-items: center;
        }

        /* 首页按钮样式 */
        .home-button {
            background-color: rgba(255, 255, 255, 0.2);
            padding: 8px 15px;
            border-radius: 20px;
            margin-right: 15px;
            transition: all 0.3s ease;
        }

        .home-button:hover {
            background-color: rgba(255, 255, 255, 0.3);
        }

        body.dark-mode .home-button {
            background-color: rgba(255, 255, 255, 0.1);
        }

        body.dark-mode .home-button:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }

        /* 模式切换按钮样式 */
        .theme-toggle {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: #f0f0f0;
            border: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
            margin-right: 15px;
        }

        .theme-toggle:hover {
            background-color: #e0e0e0;
            transform: rotate(15deg);
        }

        .theme-toggle svg {
            width: 20px;
            height: 20px;
            fill: #666;
        }

        /* 暗色模式样式 */
        body.dark-mode {
            background-color: #1a1a1a;
            color: #e0e0e0;
        }

        body.dark-mode .header {
            background-color: #2a2a2a;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        }

        body.dark-mode .category-title {
            background-color: #3a3a3a;
            color: #e0e0e0;
        }

        body.dark-mode .category-title:hover {
            background-color: #4a4a4a;
        }

        body.dark-mode .category-dropdown {
            background-color: #2a2a2a;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
        }

        body.dark-mode .category-item {
            color: #e0e0e0;
        }

        body.dark-mode .category-item:hover {
            background-color: #3a3a3a;
        }

        body.dark-mode .user-avatar {
            background-color: #3a3a3a;
        }

        body.dark-mode .user-avatar:hover {
            background-color: #4a4a4a;
        }

        body.dark-mode .user-avatar.visitor::after {
            color: #999;
        }

        /* 类别目录样式 */
        .category-nav {
            position: relative;
            display: flex;
            align-items: center;
        }

        .category-title {
            background-color: #f0f0f0;
            padding: 8px 15px;
            border-radius: 20px;
            cursor: pointer;
            font-weight: bold;
            color: #666;
            transition: all 0.3s ease;
            user-select: none;
        }

        .category-title:hover {
            background-color: #e0e0e0;
        }

        .category-dropdown {
            position: absolute;
            top: 100%;
            left: 0;
            margin-top: 10px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            overflow: hidden;
            z-index: 1000;
            display: none;
            min-width: 150px;
        }

        .category-nav:hover .category-dropdown {
            display: block;
        }

        .category-item {
            padding: 12px 15px;
            cursor: pointer;
            transition: background-color 0.3s ease;
            color: #333;
            white-space: nowrap;
        }

        .category-item:hover {
            background-color: #f5f5f5;
        }



        /* 内容容器样式 */
        .content-container {
            max-width: 1200px;
            margin: 20px auto;
            padding: 0 20px;
        }

        .content-container h1 {
            margin-bottom: 20px;
            color: #333;
            font-size: 28px;
            text-align: center;
        }

        /* 通用内容区块样式 */
        .content-section {
            background-color: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        body.dark-mode .content-section {
            background-color: #2a2a2a;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        }

        /* 分类内容样式 */
        .category-content {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
        }

        .category-item-card {
            background-color: white;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            cursor: pointer;
        }

        .category-item-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
        }

        .category-item-image {
            width: 100%;
            height: 200px;
            object-fit: cover;
        }

        .category-item-info {
            padding: 15px;
        }

        .category-item-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 10px;
            color: #333;
        }

        .category-item-description {
            font-size: 14px;
            color: #666;
            line-height: 1.5;
        }

        body.dark-mode .category-item-card {
            background-color: #2a2a2a;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        }

        body.dark-mode .category-item-title {
            color: #e0e0e0;
        }

        body.dark-mode .category-item-description {
            color: #ccc;
        }

        /* 分页样式 */
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 30px;
            gap: 10px;
        }

        .pagination-button {
            padding: 8px 15px;
            background-color: white;
            border: 1px solid #ddd;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s ease;
            color: #666;
        }

        .pagination-button:hover {
            background-color: #f5f5f5;
            border-color: #aaa;
        }

        .pagination-button.active {
            background-color: rgb(135, 73, 73);
            color: white;
            border-color: rgb(135, 73, 73);
        }

        body.dark-mode .pagination-button {
            background-color: #2a2a2a;
            border-color: #444;
            color: #e0e0e0;
        }

        body.dark-mode .pagination-button:hover {
            background-color: #3a3a3a;
            border-color: #666;
        }

        body.dark-mode .pagination-button.active {
            background-color: rgb(135, 73, 73);
            border-color: rgb(135, 73, 73);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .header {
                padding: 10px 15px;
            }

            .content-container {
                padding: 0 15px;
            }

            .content-container h1 {
                font-size: 24px;
            }

            .category-content {
                grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            }
        }

        @media (max-width: 480px) {
            .header {
                flex-direction: column;
                align-items: stretch;
                gap: 10px;
            }

            .category-nav,
            .user-avatar {
                align-self: center;
            }

            .content-section {
                padding: 15px;
            }

            .category-content {
                grid-template-columns: 1fr;
            }
        }

        .login-button {
            color: white;
            text-decoration: none;
            font-weight: bold;
            padding: 8px 18px;
            border-radius: 20px;
            background-color: rgba(255, 255, 255, 0.2);
            transition: all 0.3s ease;
        }

        .login-button:hover {
            background-color: rgba(255, 255, 255, 0.3);
        }

        /* 用户头像样式 */
        .avatar-container {
            position: relative;
            margin-right: 15px;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: #f0f0f0;
            border: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
            overflow: hidden;
        }

        .user-avatar:hover {
            transform: scale(1.1);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
        }

        .avatar-img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .avatar-menu {
            position: absolute;
            top: 100%;
            right: 0;
            margin-top: 10px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            overflow: hidden;
            z-index: 1002;
            display: none;
            min-width: 120px;
        }

        .avatar-container:hover .avatar-menu {
            display: block;
        }

        .avatar-menu-item {
            display: flex;
            align-items: center;
            padding: 12px 15px;
            color: #333;
            text-decoration: none;
            transition: background-color 0.3s ease;
        }

        .avatar-menu-item:hover {
            background-color: #f5f5f5;
        }

        .menu-icon {
            margin-right: 10px;
            font-size: 16px;
        }

        .menu-text {
            font-size: 14px;
        }

        /* 暗色模式适配 */
        body.dark-mode .user-avatar {
            background-color: #3a3a3a;
        }

        body.dark-mode .avatar-menu {
            background-color: #2a2a2a;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
        }

        body.dark-mode .avatar-menu-item {
            color: #e0e0e0;
        }

        body.dark-mode .avatar-menu-item:hover {
            background-color: #3a3a3a;
        }
    </style>
    <script src="assets/js/avatarMenu.js"></script>
</head>
<body>
    <!-- 头部导航栏 -->
    <div class="header">
        <!-- 左侧导航组 -->
        <div class="nav-left">
            <!-- 首页按钮 -->
            <div class="home-button">
                <a href="index.html" style="display: flex; align-items: center; text-decoration: none; color: white;">
                    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" style="margin-right: 5px;">
                        <path d="M12 3L2 12h3v8h6v-6h4v6h6v-8h3L12 3z"/>
                    </svg>
                    <span>首页</span>
                </a>
            </div>

            <!-- 类别目录栏 -->
            <div class="category-nav">
                <div class="category-title">非遗类别</div>
                <div class="category-dropdown">
                    <div class="category-item" data-category="传统技艺">传统技艺</div>
                    <div class="category-item" data-category="传统音乐">传统音乐</div>
                    <div class="category-item" data-category="传统舞蹈">传统舞蹈</div>
                    <div class="category-item" data-category="传统戏剧">传统戏剧</div>
                    <div class="category-item" data-category="传统美术">传统美术</div>
                    <div class="category-item" data-category="曲艺">曲艺</div>
                    <div class="category-item" data-category="民间文学">民间文学</div>
                    <div class="category-item" data-category="传统医药">传统医药</div>
                    <div class="category-item" data-category="民俗">民俗</div>
                </div>
            </div>
        </div>

        <!-- 中间主题切换 -->
        <div class="nav-center">
            <button class="theme-toggle">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
                    <path d="M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z"/>
                </svg>
            </button>
        </div>

        <!-- 右侧用户设置 -->
        <div class="nav-right">
            <a href="login.html" class="login-button">登录</a>
            <!-- 用户头像功能已移除 -->
        </div>
    </div>

    <!-- 主内容区域 -->
    <div class="content-container">
        <h1 id="category-title">非遗百科 - 分类浏览</h1>

        <!-- 分类描述 -->
        <div class="content-section">
            <p id="category-description">正在加载分类内容...</p>
        </div>

        <!-- 分类内容展示 -->
        <div class="content-section">
            <h2>分类项目</h2>
            <div class="category-content" id="category-content">
                <!-- 分类项目将动态加载到这里 -->
            </div>

            <!-- 分页控件 -->
            <div class="pagination" id="pagination">
                <!-- 分页按钮将动态生成 -->
            </div>
        </div>
    </div>

    <script>
        // 类别目录栏点击事件处理
        document.querySelectorAll('.category-item').forEach(item => {
            item.addEventListener('click', function() {
                const category = this.getAttribute('data-category');
                window.location.href = `category.html?type=${encodeURIComponent(category)}`;
            });
        });



        // 为页面标题添加点击事件，跳转到首页
        document.querySelector('h1').addEventListener('click', function() {
            window.location.href = 'waterfall.html';
        });

        // 模式切换功能
        function setupThemeToggle() {
            const themeToggle = document.querySelector('.theme-toggle');
            const body = document.body;

            // 检查用户之前的主题偏好
            if (localStorage.getItem('theme') === 'dark' ||
                (!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
                body.classList.add('dark-mode');
            } else {
                body.classList.remove('dark-mode');
            }

            // 添加点击事件处理
            themeToggle.addEventListener('click', function() {
                body.classList.toggle('dark-mode');

                // 保存用户的主题偏好
                if (body.classList.contains('dark-mode')) {
                    localStorage.setItem('theme', 'dark');
                } else {
                    localStorage.setItem('theme', 'light');
                }
            });
        }

        // 初始化主题切换功能
        setupThemeToggle();

        // 获取URL参数中的分类信息
        function getCategoryFromUrl() {
            const urlParams = new URLSearchParams(window.location.search);
            return urlParams.get('type') || '传统技艺';
        }

        // 分类描述数据
        const categoryDescriptions = {
            '传统技艺': '传统技艺是中国非物质文化遗产的重要组成部分，包括各种手工技艺、工艺制作、生产技术等。这些技艺传承了千百年，是中华民族智慧的结晶。',
            '传统音乐': '中国传统音乐是中华文化的瑰宝，包括民间歌曲、器乐、宫廷音乐、宗教音乐等多种形式，具有独特的艺术魅力和文化内涵。',
            '传统舞蹈': '传统舞蹈是各族人民在长期生产生活中创造的舞蹈形式，反映了不同民族的审美情趣、风俗习惯和历史文化。',
            '传统戏剧': '中国传统戏剧是世界文化遗产的重要组成部分，包括京剧、豫剧、粤剧、越剧等多个剧种，融合了唱、念、做、打等多种艺术表现形式。',
            '传统美术': '传统美术包括绘画、雕塑、书法、民间美术等多种形式，是中华民族审美观念和艺术创造力的集中体现。',
            '曲艺': '曲艺是一种说唱艺术形式，包括相声、评书、大鼓、琴书等多种类别，以口头语言为主要表现手段。',
            '民间文学': '民间文学是劳动人民口头创作、口头流传的文学作品，包括神话、传说、故事、歌谣、谚语等多种形式。',
            '传统医药': '传统医药是中国传统医学的重要组成部分，包括中医理论、中药炮制、针灸推拿等多种治疗方法和技术。',
            '民俗': '民俗是民间风俗的简称，包括岁时节令、人生礼仪、民间信仰、民间娱乐等方面，反映了民众的生活方式和文化传统。'
        };

        // 模拟分类数据
        function generateCategoryData(category, count = 12) {
            const data = [];
            const baseId = category.charCodeAt(0);

            for (let i = 1; i <= count; i++) {
                const itemId = baseId + i;
                const randomHeight = Math.floor(Math.random() * 200) + 200;

                data.push({
                    id: itemId,
                    title: `${category}项目 ${i}`,
                    description: `这是一个关于${category}的非遗项目。${category}是中国非物质文化遗产的重要组成部分，具有悠久的历史和深厚的文化底蕴。`,
                    imageUrl: `https://picsum.photos/seed/${itemId}/400/${randomHeight}`,
                    category: category
                });
            }

            return data;
        }

        // 渲染分类内容
        function renderCategoryContent(data) {
            const contentContainer = document.getElementById('category-content');
            contentContainer.innerHTML = '';

            data.forEach(item => {
                const card = document.createElement('div');
                card.className = 'category-item-card';

                card.innerHTML = `
                    <img src="${item.imageUrl}" alt="${item.title}" class="category-item-image">
                    <div class="category-item-info">
                        <h3 class="category-item-title">${item.title}</h3>
                        <p class="category-item-description">${item.description}</p>
                    </div>
                `;

                // 点击卡片可以跳转到详情页（预留功能）
                card.addEventListener('click', function() {
                    // 预留页面跳转链接位置
                    // window.location.href = `detail.html?id=${item.id}`;
                    alert(`即将跳转到${item.title}的详情页面`);
                });

                contentContainer.appendChild(card);
            });
        }

        // 渲染分页控件
        function renderPagination(totalItems, itemsPerPage, currentPage) {
            const paginationContainer = document.getElementById('pagination');
            paginationContainer.innerHTML = '';

            const totalPages = Math.ceil(totalItems / itemsPerPage);
            const maxVisiblePages = 5;

            // 计算可见页码范围
            let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
            let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);

            // 调整起始页码，确保显示足够的页码
            if (endPage - startPage + 1 < maxVisiblePages) {
                startPage = Math.max(1, endPage - maxVisiblePages + 1);
            }

            // 上一页按钮
            if (currentPage > 1) {
                const prevButton = document.createElement('button');
                prevButton.className = 'pagination-button';
                prevButton.textContent = '上一页';
                prevButton.addEventListener('click', function() {
                    loadPage(currentPage - 1);
                });
                paginationContainer.appendChild(prevButton);
            }

            // 页码按钮
            for (let i = startPage; i <= endPage; i++) {
                const pageButton = document.createElement('button');
                pageButton.className = `pagination-button ${i === currentPage ? 'active' : ''}`;
                pageButton.textContent = i;
                pageButton.addEventListener('click', function() {
                    loadPage(i);
                });
                paginationContainer.appendChild(pageButton);
            }

            // 下一页按钮
            if (currentPage < totalPages) {
                const nextButton = document.createElement('button');
                nextButton.className = 'pagination-button';
                nextButton.textContent = '下一页';
                nextButton.addEventListener('click', function() {
                    loadPage(currentPage + 1);
                });
                paginationContainer.appendChild(nextButton);
            }
        }

        // 加载指定页码的数据
        function loadPage(pageNumber) {
            const category = getCategoryFromUrl();
            const totalItems = 30; // 模拟总数据量
            const itemsPerPage = 12; // 每页显示的条数

            // 生成当前页的数据
            const startIndex = (pageNumber - 1) * itemsPerPage;
            const endIndex = startIndex + itemsPerPage;
            const allData = generateCategoryData(category, totalItems);
            const pageData = allData.slice(startIndex, endIndex);

            // 渲染内容和分页
            renderCategoryContent(pageData);
            renderPagination(totalItems, itemsPerPage, pageNumber);
        }

        // 初始化页面
        function initCategoryPage() {
            const category = getCategoryFromUrl();

            // 更新页面标题和描述
            document.getElementById('category-title').textContent = `非遗百科 - ${category}`;
            document.getElementById('category-description').textContent = categoryDescriptions[category] || '这是一个非遗分类页面，展示该分类下的所有非遗项目。';

            // 加载第一页数据
            loadPage(1);
        }

        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', initCategoryPage);
    </script>
</body>
</html>